import { ToolTipItem } from "../../../../com/mui/manager/ToolTipItem";
import { FahunItemInfo } from "./FahunItemInfo";
import { AmuletSpiritConfig } from "../../resource/AmuletSpiritConfig";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { LoaderPriority } from "../../../../com/gengine/resource/LoaderPriority";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { ToolTipInfo } from "../../model/ToolTipInfo";
import { Language } from "../../../../extend/language/Language";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { EquipmentUtil } from "../common/util/EquipmentUtil";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { NormalTooltip } from "../common/tooltip/NormalTooltip";
import { TAmuletSpiritConfig } from "../../../../Message/Db/Tables/TAmuletSpiritConfig";
//class FahunItem
    
    export  class FahunItem extends ToolTipItem
    {
        constructor(arg1: Boolean=true, arg2: number=32, arg3: number=32)
        {
            super();
            this._isBorder = arg1;
            this.init();
            this._iW = arg2;
            this._iH = arg3;
            this.addEventListener(flash.events.MouseEvent.ROLL_OVER, this.onMouseOverHandler);
            return;
        }

        public get fahunItemInfo(): FahunItemInfo
        {
            return this._fahunItemInfo;
        }

        public set fahunItemInfo(arg1: FahunItemInfo)
        {
            this._fahunItemInfo = arg1;
            if (this._fahunItemInfo) 
            {
                this._configInfo = AmuletSpiritConfig.instance.getConfigByLevel(this._fahunItemInfo.level);
                LoaderManager.instance.load("fhIcon" + this._fahunItemInfo.index + ".jpg", this.onLoadCompleteHandler, LoaderPriority.LevelB);
            }
            else 
            {
                this.clear();
            }
            return;
        }

        public move(arg1: number, arg2: number): void
        {
            this.x = arg1;
            this.y = arg2;
            return;
        }

        /* internal  */init(): void
        {
            if (this._isBorder) 
            {
                ObjCreate.createBitmap(ImagesConst.equipment_boarder, 0, 0, this);
            }
            this._iconBitmap = new Object /* flash.display.Bitmap */();
            if (this._isBorder) 
            {
                this._iconBitmap.x = 10;
                this._iconBitmap.y = 10;
            }
            this.addChild(this._iconBitmap);
            return;
        }

        /* internal  */onLoadCompleteHandler(arg1: ImageInfo): void
        {
            this._iconBitmap.bitmapData = arg1.bitmapData;
            if (this._iconBitmap) 
            {
                this._iconBitmap.width = this._iW;
                this._iconBitmap.height = this._iH;
            }
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.toolTipData = this.getToolTipData();
            return;
        }

        protected getToolTipData(): ToolTipInfo
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            if (this._fahunItemInfo) 
            {
                loc1 = [];
                loc2 = "";
                loc3 = Language.getStringByParam(58017, GameDefConfig.instance.getFahunName(this._fahunItemInfo.index));
                loc2 = loc2 + loc3;
                loc2 = loc2 + Language.getStringByParam(58030, this._fahunItemInfo.level);
                loc2 = loc2 + Language.getString(58031);
                if (this._configInfo) 
                {
                    if (this._configInfo.attrAdd == "0") 
                    {
                        loc2 = loc2 + Language.getString(58033);
                    }
                    else 
                    {
                        loc4 = EquipmentUtil.getAttrArray(this._configInfo.attrAdd);
                        loc6 = 0;
                        while (loc6 < loc4.length) 
                        {
                            loc5 = loc4[loc6] as Map<any, any> /* flash.utils.Dictionary */;
                            loc2 = loc2 + ("    " + HTMLUtil.addColor(loc5["name"] + "   +" + loc5["value"], "#00ff00") + "\n");
                            ++loc6;
                        }
                    }
                    loc2 = loc2 + Language.getString(58032);
                    if (this._configInfo.wuxingAdd > 0) 
                    {
                        loc2 = loc2 + ("    " + HTMLUtil.addColor(Language.getString(33079) + "   +" + this._configInfo.wuxingAdd, "#00ff00"));
                    }
                    else 
                    {
                        loc2 = loc2 + Language.getString(58034);
                    }
                }
                else 
                {
                    loc2 = loc2 + ("    " + Language.getString(58033));
                    loc2 = loc2 + Language.getString(58032);
                    loc2 = loc2 + ("    " + Language.getString(58034));
                }
                loc2 = "<textFormat leading=\'7\'>" + loc2 + "</textFormat>";
                loc1.push(loc2);
                if (!this._toolTipInfo) 
                {
                    this._toolTipInfo = new ToolTipInfo(NormalTooltip.ToolTipRenderType_Separate, loc1);
                }
                this._toolTipInfo.tooltipData = loc1;
                return this._toolTipInfo;
            }
            return null;
        }

        /* internal  */clear(): void
        {
            this._iconBitmap.bitmapData = null;
            this._fahunItemInfo = null;
            return;
        }

        /* internal */ /* var */_iconBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_fahunItemInfo: FahunItemInfo;

        /* internal */ /* var */_isBorder: Boolean;

        /* internal */ /* var */_iW: number;

        /* internal */ /* var */_iH: number;

        protected /* var */_configInfo: TAmuletSpiritConfig;

        protected /* var */_toolTipInfo: ToolTipInfo;
    }
